package com.example.hutooldemo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Console;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.hutooldemo.properties.CommonProperties;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;

/**
 * @author by linenxi
 * @Classname ExcelController
 * @Description
 * @Date 2019/5/8
 */
@RestController
public class ExcelController {

    @Autowired
    private ExcelUtil excelUtil;

    @GetMapping("getOSSURL")
    public String getOSSURL() {
        String excelOssUrl = excelUtil.getExcelOssUrl(init(), Lists.newArrayList("姓名", "年龄", "成绩", "是否通过", "localTime", "普通时间"), "ossExcelUrl", "测试导出excelOSSURL");
        return excelOssUrl;
    }

    @GetMapping("download")
    public void download() {
        excelUtil.getExcelClient(init(), Lists.newArrayList("姓名", "年龄", "成绩", "是否通过", "localTime", "普通时间"), "测试导出excelOSSURL");
    }

    private List init() {
        TestBean bean1 = new TestBean();
        bean1.setName("张三1");
        bean1.setAge(22);
        bean1.setPass(true);
        bean1.setScore(66.30);
        bean1.setExamDate(DateUtil.date());
        TestBean bean2 = new TestBean();
        bean2.setName("李四1");
        bean2.setAge(28);
        bean2.setPass(false);
        bean2.setScore(38.50);
        bean2.setExamDate(DateUtil.date());
        List<TestBean> rows = CollUtil.newArrayList(bean1, bean2);
        return rows;
    }

}
